import { BaseWindow } from "../../../component/window/BaseWindow";
import { ItemData } from "../../resource/info/ItemData";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { MailEventName } from "./MailEventName";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
//class InputAmountPanel
    
    export  class InputAmountPanel extends BaseWindow
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public set itemData(arg1: ItemData)
        {
            this._itemData = arg1;
            return;
        }

        public init(): void
        {
            titleHeight = 30;
            this.setSize(248, 120);
            this._titleLabel = new GLabel();
            this._titleLabel.htmlText = HTMLUtil.addColor(Language.getString(52010), "#F5FF02");
            this._titleLabel.mouseChildren = false;
            this._titleLabel.mouseEnabled = false;
            this._titleLabel.move(92, 10);
            this.addChild(this._titleLabel);
            this._amountLabel = new GLabel();
            this._amountLabel.htmlText = HTMLUtil.addColor(Language.getString(52011), "#B1F0FF");
            this._amountLabel.move(30, 50);
            this.addChild(this._amountLabel);
            this._amountInput = ObjCreate.createGTextInput(80, 50, 90, 20, this);
            this._amountInput.text = "1";
            this._okBtn = new GButton();
            this._okBtn.label = Language.getString(52012);
            this._okBtn.styleName = "Button";
            this._okBtn.setSize(46, 27);
            this._okBtn.move(54, 80);
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOkBtnClickHandler);
            this.addChild(this._okBtn);
            this._cancelBtn = new GButton();
            this._cancelBtn.label = Language.getString(52013);
            this._cancelBtn.styleName = "Button";
            this._cancelBtn.setSize(46, 27);
            this._cancelBtn.move(144, 80);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnClickHandler);
            this.addChild(this._cancelBtn);
            return;
        }

        /* internal  */onOkBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=int(this._amountInput.text);
            if (loc1 < 0 || loc1 > this._itemData.itemAmount) 
            {
                Alert.show(Language.getString(52014), null, Alert.OK | Alert.CANCEL, null);
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(MailEventName.INPUT_AMOUNT_OK, {"uid": this._itemData.uid, "amount": loc1}));
            this.onCancelBtnClickHandler(null);
            return;
        }

        /* internal  */onCancelBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.parent) 
            {
                this.parent.removeChild(this);
            }
            return;
        }

        /* internal */ /* var */_titleLabel: GLabel;

        /* internal */ /* var */_amountLabel: GLabel;

        /* internal */ /* var */_amountInput: GTextInput;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_itemData: ItemData;
    }
